
//
//  musicTools.swift
//  QQMusic
//
//  Created by xmg on 16/9/7.
//  Copyright © 2016年 wlis. All rights reserved.
//

import UIKit
import AVFoundation
class musicTools: NSObject {

    static var player : AVAudioPlayer?
    class func playMusicWithFileName (fileName : String) -> AVAudioPlayer?{
        /** 获取url */
        guard let musicUrl = NSBundle.mainBundle().URLForResource(fileName, withExtension: nil) else{ return  nil }
        /** 判断是否是原来歌曲 */
        if (player?.url != nil && player!.url!.isEqual(musicUrl)) {
            player?.play()
            return player
        }
        /** 创建播放器 */
        guard let player = try? AVAudioPlayer(contentsOfURL: musicUrl) else{
        return nil
        }
        self.player = player
        return player
    }
}
